package com.study.thread.interrupt;
/*
    t1.interrupt(); // 表示中断t1线程，此时不是真正中断不知醒了，只是给他一个标示设置为true，需要线程里用Thread.currentThread().isInterrupted()判断是否中断

    Thread.currentThread().isInterrupted() //获取当前线程中断标志，如果已经中断（也就是别人调用了这个线程的intrrupt()方法）返回true，如果没中断是可以运行的返回false
    //且里面调用的，isInterrupted(false); false参数表示不清除中断标志
 */
public class InterruptDemo1 {

    public static void main(String[] args) {

        Thread t1 = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                try {

                    System.out.println("执行interrupt，当前中断标示：" + Thread.currentThread().isInterrupted());
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("异常中断interrupt，当前中断标示：" + Thread.currentThread().isInterrupted());
                }
            }
            System.out.println("执行interrupt结束，当前中断参数：" + Thread.currentThread().isInterrupted());
        });
        t1.start();
        try {
            Thread.sleep(1000);
            t1.interrupt();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
